<?php
use Workerman\Worker;
use React\EventLoop\Factory;

$worker = new Worker('tcp://0.0.0.0:1234');
$worker->count=3;
$worker->onWorkerStart = function() {
    global $factory, $loop;
    $loop  = Worker::getEventLoop();
    //$factory = new Factory($loop);
    //$factory = new Factory($loop);
    $loop = React\EventLoop\Factory::create();
};
$worker->onMessage = function($connection, $data)
{   
    global $factory, $loop;

    $timer = $loop->addTimer(0, function () {
        echo 'tick!' . PHP_EOL;
    });
    $loop->addTimer(0, function () use ($loop, $timer) {
        $loop->cancelTimer($timer);
        echo 'OK' . PHP_EOL;
    });
    $loop->addTimer(0, function () use ($loop, $timer) {
        $loop->cancelTimer($timer);
        echo 'Done' . PHP_EOL;
    });
    

    $connection->send("HTTP/1.1 200 OK\r\nConnection: keep-alive\r\nServer: workerman\r\nContent-Length: 5\r\n\r\nhello");
    $loop->run();
};
if(!defined('GLOBAL_START'))
{
    Worker::runAll();
}